#ifndef __WIN_DEBUG_BUFFER_H__
#define __WIN_DEBUG_BUFFER_H__

#include <windows.h>
#include <atlbase.h>
#include <atlstr.h>
#include <vector>
#include <string>


typedef void (*WinDebugMonitorCallbackFunc)(INT, LPCSTR);
typedef struct _SDBWinBuffer
{
	DWORD   dwProcessId;
	char    data[4096-sizeof(DWORD)];
} SDBWinBuffer;


class CWinDebugMonitor
{
private:
    enum {
        TIMEOUT_WIN_DEBUG    =    100,
    };


private:
    HANDLE	m_hDBMonBuffer;
    HANDLE	m_hEventBufferReady;
    HANDLE	m_hEventDataReady;
	HANDLE  m_hEventClose;

    HANDLE	m_hWinDebugMonitorThread;
    SDBWinBuffer *m_pDBBuffer;

	DWORD	m_lastID;
	bool	m_newLine;
	WinDebugMonitorCallbackFunc m_Callback;
private:
    DWORD WinDebugMonitorProcess();
    static DWORD WINAPI WinDebugMonitorThread(void *pData);

public:
	DWORD Initialize(CComBSTR prefix=L"");
    void Unintialize();
    CWinDebugMonitor();
    ~CWinDebugMonitor();

	void SetCallback(WinDebugMonitorCallbackFunc func){ m_Callback=func; }
public:
    virtual void OutputWinDebugString(const char *str) {};
};

#endif